#!/usr/bin/perl

use Archive::Tar;
use IO::Uncompress::Gunzip;
use FindBin;
use File::Path;
use Cwd;

my $script_path = $FindBin::Bin;
my $orig_path = getcwd;
my $tmp_root = $ENV{TMP_DIR} || '/tmp';
my $tmp_path = $tmp_root . '/pafl-' . time;

mkpath($tmp_path);
chdir($tmp_path);

my $z = new IO::Uncompress::Gunzip \*DATA;
my $tar = Archive::Tar->new($z);
$tar->extract;

chdir($orig_path);

system("PAFL_SCRIPT_PATH=\"$script_path\" perl $tmp_path/pafl @ARGV");

rmtree($tmp_path);

__DATA__
